leap year checker

def is_leap_year(year): # A year is a leap year if it is divisible by 4 # but not divisible by 100, unless also divisible by 400 if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): return True return False try: year = int(input("Enter a year: ")) if is_leap_year(year): print(f"{year} is a leap year.") else: print(f"{year} is not a leap year.") except ValueError: print("Please enter a valid year.")

Code output

Enter a year: 2024 2024 is a leap year.